package com.hu.zhcc.shiro.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hu.zhcc.shiro.dao.TemplateMapper;
import com.hu.zhcc.shiro.entity.bo.Template;
import com.hu.zhcc.shiro.entity.vo.TemplateVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TemplateServiceImpl implements TemplateService{

    @Autowired
    private TemplateMapper templateMapper;

    @Override
    public boolean AddTemplate(Template Template) {
            return templateMapper.insert(Template)>0;
    }
    //分页查询
    @Override
    public PageInfo<Template> pageQuery(TemplateVO TemplateVO) {
        PageHelper.startPage(TemplateVO.getPageNum(),TemplateVO.getPageSize());
        List<Template> byCondition = templateMapper.findByCondition(TemplateVO.getQueryString());
        PageInfo<Template> checkItemPageInfo = new PageInfo<>(byCondition);
        return checkItemPageInfo;
    }

    @Override
    public boolean updateTemplate(Template Template) {
        return templateMapper.updateByPrimaryKey(Template)>0;
    }

    @Override
    public boolean removeTemplate(Short id) {
        return templateMapper.deleteByPrimaryKey(id)>0;
    }

    @Override
    public boolean updateTemplate(Short id) {
        Template template = templateMapper.selectByPrimaryKey(id);
        String invoke = template.getInvoke();
        if(invoke.equals("禁用")){
            template.setInvoke("启用");
        }else if(invoke.equals("启用")){
            template.setInvoke("禁用");
        }
        return templateMapper.updateByPrimaryKey(template)>0;
    }

    @Override
    public Template findByid(Short id) {
        return templateMapper.selectByPrimaryKey(id);
    }
}
